<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <base href="<%=basePath%>">
  <meta charset="utf-8">
  <title>生产问题查询</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="layuiadmin/style/admin.css" media="all">
  <style type="text/css">
	.layui-table-cell .layui-form-radio {
		position: relative;
		top: 50%;
	}
  </style>
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">生产编号</label>
            <div class="layui-input-inline">
              <input type="text" name="producecode" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">批次号</label>
            <div class="layui-input-inline">
              <input type="text" name="batchno" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-produceproduct-contlist-search">
              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
          </div>
        </div>
      </div>
      <div class="layui-card-body">
        <table id="LAY-produceproduct-content-list" lay-filter="LAY-produceproduct-content-list"></table> 
        <script type="text/html" id="toolbarDemo">
  			<div class="layui-btn-container">
				<button class="layui-btn layuiadmin-btn-list" lay-event="indepot">产品入库</button>
				<button class="layui-btn layuiadmin-btn-list" lay-event="productScrap">产品报废</button>
  			</div>
		</script>
      </div>
    </div>
  </div>

  <script src="layuiadmin/layui/layui.js"></script>  
  <script>
  layui.config({
    base: 'layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'contlist', 'table', 'laydate'], function(){
    var table = layui.table
    ,admin = layui.admin
    ,laydate = layui.laydate
    ,form = layui.form;
    
    laydate.render({
		elem: '#date', //弹出页的指定元素生日时期需要为时间格式
	});
    
    table.render({
        elem: '#LAY-produceproduct-content-list'
        ,url:'producescheduleproblem/findListJson/'
        ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
        ,cols: [[
           {type:'radio'}          
		  ,{type:'numbers', title: '序号'}
		  ,{field:'prisonername', title: '生产人员', sort: true}
		  ,{field:'producecode', title: '生产任务编号', sort: true}
		  ,{field:'productname', title: '产品名称', sort: true}
          ,{field:'linename', title: '生产线', sort: true}
          ,{field:'batchno', title: '批次号', sort: true}
          ,{field:'ordername', title: '工序', sort: true}
          ,{field:'problemname', title: '问题名称', sort: true}
          ,{field:'addtime', title: '生产时间', sort: true}
        ]]
    	,page: true
      });
    
    //监听搜索
    form.on('submit(LAY-produceproduct-contlist-search)', function(data){
      var field = data.field;
      //执行重载
      table.reload('LAY-produceproduct-content-list', {
        where: field
        ,page: {
            curr: 1 //重新从第 1 页开始
        }
      });
    });
    
    //头工具栏事件
    table.on('toolbar(LAY-produceproduct-content-list)', function(obj){
      
      switch(obj.event){
        case 'indepot':  //产品入库
        	var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            
            if(data.length === 0){
                return layer.msg('请选择数据');
            }
            
            if(data[0].productstatus != '生产完成'){
                return layer.msg('该产品不是生产完成状态，不能入库!');
            }
            
            layer.confirm('确定入库 ?', function(index){
            	layer.msg('正在提交请稍候。。。', {icon: 16,time:'-1',shade : [0.5 , '#000' , true]});
	        	admin.req({
	      		     url: 'produceproduct/saveIndepot?id='+data[0].id //实际使用请改成服务端真实接口
     		    	//,data: JSON.stringify(data)
	     	        ,type: 'POST'
	     	        ,contentType: "application/json;charset-UTF-8"
	     	        ,done: function(res){
	     	        	layer.msg(res.msg);
	     	         	//关闭网页
	    	          	layer.close(index);
	     	         	table.reload('LAY-produceproduct-content-list');
	     	         }
	           });
            });
        break;   
        
        case 'productScrap':  //产品报废
        	var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            
            if(data.length === 0){
                return layer.msg('请选择数据');
            }
            
            if(data[0].productstatus != '待返工'){
                return layer.msg('该产品不是待返工状态，不能报废!');
            }
            
            layer.confirm('确定报废 ?', function(index){
            	layer.msg('正在提交请稍候。。。', {icon: 16,time:'-1',shade : [0.5 , '#000' , true]});
	        	admin.req({
	      		     url: 'produceproduct/saveProductScrap?id='+data[0].id //实际使用请改成服务端真实接口
     		    	//,data: JSON.stringify(data)
	     	        ,type: 'POST'
	     	        ,contentType: "application/json;charset-UTF-8"
	     	        ,done: function(res){
	     	        	layer.msg(res.msg);
	     	         	//关闭网页
	    	          	layer.close(index);
	     	         	table.reload('LAY-produceproduct-content-list');
	     	         }
	           });
            });
        break;   
         
      };
    });
  });
 
  
  </script>
</body>
</html>